< previous page page_431 next page >

Page 431
The Form_Load() event calls the routine FormShow() to get the data from the Employee table:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub FormShow()
   Dim oRS As Recordset
   Dim strSQL As String

   ' Build SQL for loading list box
   strSQL = "SELECT * "
   strSQL = strSQL & "FROM tblEmployees "
   strSQL = strSQL & "WHERE lEmp_id = " & mlngEmpID

   Set oRS = New Recordset

   oRS.Open strSQL, ConnectString(), _
            adOpenForwardOnly, adLockReadOnly
   With oRS
      txtEmpID = mlngEmpID
      txtFirst = !sFirst_nm & ""
      txtLast = !szLast_nm & ""
      txtAddress = !szStreet1_ad & ""
      txtCity = !szCity_nm & ""
      txtState = !sState_cd & ""
      txtZip = !sZip_cd & ""
   End With
End Sub
In the code above you can see the SQL statement that will retrieve on unique rows from the employee table based on the employee ID. When you open the Recordset, you pass in the SQL string as well as a connection string. Instead of coding this string right here, I call a function, named ConnectString(), that returns this string to the Open method.
Lets code the Edit button so that a new instance of the Employee form is loaded for each Click event. This way, each form can display a different employee:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdEdit_Click()
   Dim frmNewEmp As frmEmployee

   Set frmNewEmp = New frmEmployee

 
< previous page page_431 next page >

If you like this book, buy it!